// pages/cinema/cinema.js
var Tx = require('../../utils/qqmap-wx-jssdk.js');
var qqmapsdk = new Tx({
    key: 'TKOBZ-S6UCP-B4YDB-LQZJF-5JNB2-WGBUX' // 必填
});  
Page({

    data: {
        city:"",
        address:"",
        cinemaList:[]
    },
    // 获取定位
    position(){
        var _this = this
        wx.getLocation({
           success(res){
            //    console.log(res);
               qqmapsdk.reverseGeocoder({
                success: function(val) {
                    // console.log(val);
                    _this.setData({
                        city:val.result.address_component.city,
                        address:val.result.address
                    })
                    // 搜索结果
                    qqmapsdk.search({
                        keyword: '影院',
                        location: `${res.latitude},${res.longitude}`,
                        success: function (cin){
                            console.log(cin);
                                cin.data.forEach(el => {
                                    el._distance = (el._distance/1000).toFixed(2)
                                    // console.log(el);
                                    
                                });      
                            _this.setData({
                                cinemaList:cin.data
                            })  
                        }
                    })
               }
           })
        }
    })
    },
    onShow(){
        this.position()
    }
})